﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UObj = UnityEngine.Object;

namespace GameFrameWork
{
    public static partial class LoopRunnerHelper
    {
        /// <summary>
        /// 要注意自己释放
        /// </summary>
        public static LoadAssetAwaiter GetLoader(string assetName, int priority = 0, Type assetType = null)
        {
            return new LoadAssetAwaiter(assetName, priority, assetType);
        }
        public static async Task<UObj> LoadAsset(string assetName, int priority = 0, Type assetType = null)
        {
            return await LoadAsset<UObj>(assetName, priority, assetType);
        }
        public static async Task<T> LoadAsset<T>(string assetName, int priority = 0, Type assetType = null) where T : UObj
        {
            var loader = new LoadAssetAwaiter(assetName, priority, assetType);
            var asset = await loader;
            loader.Unload();
            return asset as T;
        }
        /// <summary>
        /// 加载后自动释放  主要用于真机环境下先下载资源
        /// </summary>
        public static async Task PreloadAsset(string assetName)
        {
            var loader = GetLoader(assetName);
            await loader;
            loader.Unload();
        }
    }
}

